package arith;

import java.util.Random;

public class Exponent implements Input {
	
	int number;
	int exponent;
	String prob;
	
	public Exponent(int n, int e, String s){
		number = n;
		exponent = e;
		prob = s;
	}
	
	public Numbers add(Exponent e){
		return new Numbers(this.value()+e.value(), this.toString() + " + " + e.toString());
	}
	
	public Numbers sub(Exponent e){
		return new Numbers(this.value()-e.value(), this.toString() + " - " + e.toString());
	}
	
	public Exponent mult(Exponent e){
		if(e.number != this.number){
			e.number = this.number;
		}
		Random randomGenerator = new Random();
		int r = randomGenerator.nextInt(2);
		if(r == 0){
			return new Exponent(number, (this.exponent+e.exponent), this.toString() + " * " + e.toString());
		}else{
			return new Exponent(number, (this.exponent*e.exponent), "("+this.toString()+")^"+e.exponent);
		}
	}
	
	public Exponent div(Exponent e){
		if(e.number != this.number){
			e.number = this.number;
		}
		return new Exponent(number, this.exponent-e.exponent, this.toString() + " / " + e.toString());
	}

	public String toString(){
		if(exponent == 1){
			return "" + number;
		}
		return number + "^" + exponent;
	}
	
	public int id() {
		return 2;
	}

	public double value() {
		double total = 1;
		for(int i=0; i<exponent; i++){
			total = total*number;
		}
		return total;
	}
}